package com.fw.filter;
import com.fw.model.Permission;
import com.fw.model.User;
import com.fw.service.UserService;
import com.fw.service.impl.UserServiceImpl;
import com.fw.util.SessionUser;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;

public class UrlFilter implements Interceptor{

	@Override
	public void intercept(Invocation inv) {
		UserService userService = new UserServiceImpl();
		String key = inv.getActionKey();
		SessionUser su = inv.getController().getSessionAttr("sessionUser");
		Permission permisson = new Permission();
		permisson.set("p_url", key);
		System.out.println("key:"+key);
		User user = new User().set("u_id", su.getUserId());
		boolean flag = userService.userIsPermissionService(user, permisson);
		if(flag) 
		inv.invoke();
		else inv.getController().renderJson("权限不足");
	}

}
